﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace movie.tool.library.binding
{
    public class NotifyPropertyChanged : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        /// <summary>
        /// 发送通知消息
        /// </summary>
        /// <param name="propetyName">属性名称字符串</param>
        protected void SendPropertyChanged(string propetyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propetyName));
            }
        }
        /// <summary>
        /// 通过Lambda表达式发送通知消息
        /// </summary>
        /// <param name="propertyLambda">访问属性的Lambda表达式</param>
        protected void SendPropertyChanged(Expression<Func<object>> propertyLambda)
        {
            SendPropertyChanged(PropertyName.Get(propertyLambda));
        }
    }
}
